<% layout('/layouts/default.html', {title: '单项指标', libs: ['layout','dataGrid','inputmask','ueditor']}){ %>
<div class="ui-layout-west">
    <div class="main-content">
        <div class="box box-main">
            <div class="box-header" style="padding-bottom: 4px;">
                <div class="box-title">
                    <i class="fa icon-grid"></i> ${text('关键考核指标')}
                </div>
            </div>
            <div class="box-body">
                <div class="input-group">
                    <#form:input path="unitName" maxlength="100" class="form-control " placeholder="请输入单位名称" autocomplete="off"/>
                    <span class="input-group-addon"  style="cursor: pointer" onclick="searchTaskDesc()">查询</span>
                    <span class="input-group-addon" onclick="reset()" style="cursor: pointer">重置</span>
                </div>
            </div>
            <div class="ui-layout-content">
                <table id="leftDataGrid"></table>
            </div>
        </div>
    </div>
</div>
<div class="ui-layout-center">
    <iframe id="mainFrame" name="mainFrame" class="ui-layout-content p0"></iframe>
</div>
<% } %>
<script>
    // 初始化布局
    $('body').layout({
        west__initClosed: $(window).width() <= 767, // 是否默认关闭
        west__size: 200,
        onresize_end: function(){
            $('#leftDataGrid').dataGrid('resize');
        }
    });
    var win = $("#mainFrame")[0].contentWindow;

    $('#leftDataGrid').dataGrid({
        data: ${toJson(assessmentUnit)},
        datatype: "local", // 设置本地数据
        sortableColumn:false, // 禁止排序
        autoGridHeight: function(){
            var height = $(window).height()-170;
            return height;
        }, // 设置自动高度
        columnModel: [
            {header:'${text("任务id")}', name:'examId',hidden:true, width:150, align:"left"},
            {header:'${text("被考核单位code")}', name:'exameOrg',hidden:true, width:150, align:"left"},
            {header:'${text("被考核单位")}', name:'exameOrgName', width:150, align:"left",formatter: function(val, obj, row, act){
                    let text="("+js.getDictLabel(${@DictUtils.getDictListJson('dc_exam_score_status')}, row.exameStatus, '${text("未知")}', true)+")";
                    if (row.exameStatus=="4"){
                        return val+'<span style="color: red">'+text+'</span>';
                    }else if (row.exameStatus=="5"){
                        return val+'<span style="color: blue">'+text+'</span>';

                    }
                    return val;

            }},
            {header:'${text("评分状态")}', name:'exameStatus',hidden:true, width:150, align:"left"},
        ],
        emptyDataHint: true,
        // 选择行后调用（id:行id，isSelect：是否是选中，event：事件）
        onSelectRow: function(id, isSelect, event) {
            let selectRow = $('#leftDataGrid').dataGrid('getRowData', id);
            $('#mainFrame').attr('src', '${ctx}/score/dcSupExamGJZBScore/subView?examId=${examId}&exameOrg='+selectRow.exameOrg);
        },
        // 加载成功默认设置选择第一个
        ajaxSuccess: function(data){
            if (data.total>0){
                changePage(data,'${selectExamOrg}')
            }
            $('#leftDataGrid tr').click(function(){
                $(this).siblings().removeClass('SelectBG');
                $(this).addClass('SelectBG');
            })
        }
    });


    function changePage(data,exameOrg){
        if (typeof exameOrg!="undefined"&&exameOrg!=''){
            for (let i = 0; i <data.rows.length; i++) {
                if (data.rows[i].exameOrg==exameOrg){
                    $('#mainFrame').attr('src', '${ctx}/score/dcSupExamGJZBScore/subView?examId=${examId}&exameOrg='+data.rows[i].exameOrg);
                    $('#leftDataGrid tr').eq(i+1).addClass('SelectBG')
                    break;
                }
            }
        }else {
            let row=data.rows[0];
            $('#mainFrame').attr('src', '${ctx}/score/dcSupExamGJZBScore/subView?examId=${examId}&exameOrg='+row.exameOrg);
            $('#leftDataGrid tr').eq(1).addClass('SelectBG')

        }
    }


    function searchTaskDesc() {
        // 获取用户输入查询项
        let tempTaskDesc = $("#unitName").val();
        if(tempTaskDesc != '' && tempTaskDesc != undefined){
            // 记录目标值
            let targetList = [];
            // 遍历表格数据，获取目标值
            let tempList = ${toJson(assessmentUnit)}
            for(let i = 0; i < tempList.length; i++){
                if(tempList[i].exameOrgName.indexOf(tempTaskDesc) != -1){
                    targetList.push(tempList[i]);
                }
            }
            // 刷新表格数据
            $('#leftDataGrid').dataGrid('setParam', {
                data:targetList
            }, true).dataGrid('reloadGrid');
        }else {
            $('#leftDataGrid').dataGrid('setParam', {
                data:${toJson(assessmentUnit)}
            }, true).dataGrid('reloadGrid');
        }
    }

    // 重置表格数据
    function reset() {
        // 重置查询项
        $("#unitName").val('');
        // 重置表格数据
        $('#leftDataGrid').dataGrid('setParam', {
            data:${toJson(assessmentUnit)}
        }, true).dataGrid('reloadGrid');
    }
</script>
<style>
    .SelectBG td{
        background: #eaeaea !important;
        background-color: #eaeaea !important;
        color:blue;
    }
</style>